<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="s_model" :rules="rules" label-width="100px" id="mvcfm">
          <el-button @click="popAddModel('')" type='success' size="mini"><i class='fa fa-plus'></i>增加型号</el-button>
          <el-button @click="d_batch_model('')" type='success' size="mini"><i class='fa fa-check'></i>批量删除</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 型号列表 </span>
          </div>
          <el-table :data="pageList" v-loading="loading" @selection-change="handleSelectionChange">
            <el-table-column label="操作" align="center" width='100' type=''>
              <template slot-scope="scope">
                <el-dropdown trigger="click">
                  <span class="el-dropdown-link">操作<i class="el-icon-arrow-down el-icon--right"></i></span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-link @click="d_model('&CMIDmodel_id='+scope.row.model_id+'')">删除</el-link>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-link @click="popModifyModel('&CMIDmodel_id='+scope.row.model_id+'')">修改</el-link>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-link @click="gotoPage('/mes/certificate/KeyComponent?CMIDmodel_id='+scope.row.model_id+''+vueparams+'')">关联规格</el-link>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
            <el-table-column label="#" align="center" type='index'>
            </el-table-column>
            <el-table-column label="#" align="center" type='selection'>
            </el-table-column>
            <el-table-column label="型号" prop="model_id">
              <template slot-scope="scope">
                <el-link @click="popAddCorrelationSpecification('&CMIDmodel_id='+scope.row.model_id+'')" type='primary'>{{scope.row.model}}</el-link>
              </template>
            </el-table-column>
            <el-table-column label="规格" prop="cer_norm_name">
            </el-table-column>
            <el-table-column label="增加时间" prop="entered">
            </el-table-column>
          </el-table>
          <pagination v-show="total>0" :total="total" :limit.sync="pageSize" @pagination="getPage" />
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'适用型号'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="AddModelVisible" append-to-body>
      <AddModel v-if="AddModelVisible" ref="AddModel" :popparams="popparams"> </AddModel>
    </el-dialog>
    <el-dialog :visible.sync="ModifyModelVisible" append-to-body>
      <ModifyModel v-if="ModifyModelVisible" ref="ModifyModel" :popparams="popparams"> </ModifyModel>
    </el-dialog>
    <el-dialog :visible.sync="AddCorrelationSpecificationVisible" append-to-body>
      <AddCorrelationSpecification v-if="AddCorrelationSpecificationVisible" ref="AddCorrelationSpecification" :popparams="popparams"> </AddCorrelationSpecification>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import AddModel from "@/views/mes/certificate/AddModel";
  import ModifyModel from "@/views/mes/certificate/ModifyModel";
  import AddCorrelationSpecification from "@/views/mes/certificate/AddCorrelationSpecification";
  export default {
    name: 'ApplicableModel',
    components: {
      AddModel,
      ModifyModel,
      AddCorrelationSpecification,
    },
    props: ['popparams'],
    data() {
      return {
        AddModelVisible: false,
        AddModelValue: null,
        AddModelDesc: null,
        ModifyModelVisible: false,
        ModifyModelValue: null,
        ModifyModelDesc: null,
        AddCorrelationSpecificationVisible: false,
        AddCorrelationSpecificationValue: null,
        AddCorrelationSpecificationDesc: null,
        vueparams: this.getVUEParams(""),
        s_model: [],
        loading: true,
        pageList: [],
        pageSize: 10,
        total: null,
        Container: null,
        elcheck: [],
        multiple: true,
        rules: {}
      }
    },
    created() {
      this.getPage(1);
      this.loadContainerMenu({
        pid: "018E412E935E4B3EB6DF631BB3B46A50",
        name: "客户右菜单类型",
        selected: "适用型号"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      d_model(_params) {
        request({
          method: 'post',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/d_model?' + _params + this.vueparams,
          data: this.postData()
        }).then(data => {
          this.$router.replace("/redirect" + this.$route.fullPath);
          this.msgSuccess(data.msg);
        })
      },
      d_batch_model(_params) {
        this.$confirm("确认批量删除", "警告").then(() => {
          request({
            method: 'post',
            url: '/xcapi/VUEAction/mes/certificate/CertificateAction/d_batch_model?' + _params + this.vueparams,
            data: this.postData()
          }).then(data => {
            this.$router.replace("/redirect" + this.$route.fullPath);
            this.msgSuccess(data.msg);
          })
        });
      },
      getPage(page) {
        this.loading = true;
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/s_model?' + this.vueparams,
          params: {
            pageNo: page
          }
        }).then(data => {
          this.loading = false;
          this.pageList = data.rows;
          this.total = data.total;
        })
      },
      popAddModel(params) {
        if (params != "") this.popparams = params + this.vueparams;
        this.AddModelVisible = !this.AddModelVisible;
      },
      popModifyModel(params) {
        if (params != "") this.popparams = params + this.vueparams;
        this.ModifyModelVisible = !this.ModifyModelVisible;
      },
      popAddCorrelationSpecification(params) {
        if (params != "") this.popparams = params + this.vueparams;
        this.AddCorrelationSpecificationVisible = !this.AddCorrelationSpecificationVisible;
      },
      handleSelectionChange(selection) {
        this.elcheck = selection.map(item => item["model_id"]);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
    },
  }
</script>
